package com.home.homepage.service.prefecture.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eig.common.entity.course.EduSubject;
import com.eig.common.entity.course.EduCourse;
import com.eig.common.vo.Result;
import com.home.homepage.dao.prefecture.ZoneCourseDao;
import com.home.homepage.feign.prefecture.Coures;
import com.home.homepage.service.prefecture.ZoneCourseService;

import com.home.homepage.utils.IdWorker;
import com.home.homepage.vo.prefecture.ZoneCourseId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ：YQ袁（2446806940@qq.com）
 * @date ：Created in 2022/12/7 20:00
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class ZoneCourseServiceImpl implements ZoneCourseService {
    @Autowired
    private ZoneCourseDao zoneCourseDao;
    @Autowired
    private Coures coures;

    @Override
    public Result<IPage<EduCourse>> getAllDetail(Integer current, Integer pageSize, EduSubject eduSubject) {
        coures.findsubject(current, pageSize, eduSubject);
        return new Result(2000, "查询成功");
    }

    @Override
    public Result<IPage<EduCourse>> findCourse(Integer current, Integer pageSize, EduCourse e) {
        return coures.findCourse(current, pageSize, e);
    }

    @Resource
    private IdWorker idWorker;

    @Override
    public Result addCourseDetail(ZoneCourseId zoneCourseId) {
        //先添加在修改
        zoneCourseId.setId(idWorker.nextId());
        zoneCourseDao.addCourseDetail(zoneCourseId);
        EduCourse eduCourse = new EduCourse();
        eduCourse.setId(zoneCourseId.getCourseId());
        eduCourse.setIsAdd(1);
        coures.updateCourseById(eduCourse);
        return new Result(2000, "添加成功");
    }

    @Override
    public Result findsubject(PageRequest pageRequest, EduSubject exception , String id ) {
        PageImpl<EduSubject> page = new PageImpl<>(zoneCourseDao.queryAllByLimit(exception, pageRequest,id ));

        Map<String , Object> map = new HashMap<>();
        map.put("data",page.getContent());
        map.put("total",page.getSize());

        System.out.println(page+"@@@@@");
        return new Result(2000, "sdahs ",map);
    }

}
